package org.example.handle.tess;

import com.google.inject.Singleton;
import net.sourceforge.tess4j.ITesseract;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;
import org.example.handle.AbstractHandle;

import java.awt.image.BufferedImage;

@Singleton
public class TessOcrHandle extends AbstractHandle {

    private final ITesseract instance = new Tesseract() {{
        setDatapath(System.getProperty("user.dir") + "/config/tessdata");
    }};

    @Override
    public Object general(BufferedImage image) {
        return generalTemp(image);
    }

    @Override
    public Object generalTemp(BufferedImage image) {
        try {
            return instance.doOCR(image);
        } catch (TesseractException e) {
            return "";
        }
    }
}
